<?php
/**
 * StatZone default controller
 * 
 * @package    USS.StatZone
 * @subpackage Components
 * @link www.ugenix.co.za www.statzone.co.za
 * @license		Commercial
 * @author Salie Hendricks
 */


// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.view' );

/**
 * Teams View
 *
 * @package    USS.StatZone
 * @subpackage Components
 */
class StatZoneViewScorecards extends JView
{

    function setScorecardsToolbar()
	{
		JToolBarHelper::title(   JText::_( 'StatZone Scorecards Manager' ), 'generic.png' );
        JToolBarHelper::deleteList();
		JToolBarHelper::editListX();
		JToolBarHelper::addNewX();
	}
    
    function setSingleScorecardsToolbar()
	{
		$task = JRequest::getVar( 'task', '', 'method', 'string');

		JToolBarHelper::title( $task == 'add' ? JText::_( 'Scorecards' ) . ': <small><small>[ '. JText::_( 'New' ) .' ]</small></small>' : JText::_( 'Scorecards' ) . ': <small><small>[ '. JText::_( 'Edit') .' ]</small></small>', 'generic.png' );
		JToolBarHelper::save( 'save' );
		JToolBarHelper::apply('apply');
		JToolBarHelper::cancel( 'cancel' );
		
	}
    
	function singleScorecard( &$row, &$lists, &$statstable)
	{
		StatZoneViewScorecards::setSingleScorecardsToolbar();
		JRequest::setVar( 'hidemainmenu', 1 );
        
        //$contentlink		= JRoute::_( 'index.php?option=com_content&sectionid=-1&task=edit&cid[]='. $row->contentid );
        
		//JFilterOutput::objectHTMLSafe( $row, ENT_QUOTES, 'customclubcode' );
		?>
		<script language="javascript" type="text/javascript">
		
		
		function submitbutton(pressbutton) {
			var form = document.adminForm;
             
           var oppselection = form.oppteamid.options[form.oppteamid.options.selectedIndex].value; 
           var hometeamselection = form.hometeamid.options[form.hometeamid.options.selectedIndex].value; 
           var resultselection = form.resultlist.options[form.resultlist.options.selectedIndex].value; 
           //alert(selection);
			if (pressbutton == 'cancel') {
              submitform( pressbutton );
				return;
			}
           
			//do field validation
			if (form.season.value == "") {
				alert( "<?php echo JText::_( 'You must provide a season.', true ); ?>" );
			}
          else if (!validateSeasonFormat(form.season.value)) {
             alert( "<?php echo JText::_( 'Season must be in the format YYYY/YYYY. Example 2008/2009.', true ); ?>" );
          }
          else if (form.firstinndate.value == "") {
				alert( "<?php echo JText::_( 'You must provide a first innings date.', true ); ?>" );
          }
          else if (oppselection == "0") {
              alert( "<?php echo JText::_( 'You must select an opponent.', true ); ?>" );
			}
          else if (hometeamselection == "0") {
              alert( "<?php echo JText::_( 'You must select a team.', true ); ?>" );
			}
          else if (form.resultlist == "0") {
              alert( "<?php echo JText::_( 'You must select a result.', true ); ?>" );
			}
          else if(!inningsDatesOk())
          {
              alert("Second innings date cannot be after the first innings");
          } 
          else if(!validateScoreCardTeamScoresFormatOk())
          {
              //no need to anything here other than not let it submit
          }           
          else {
          
				submitform( pressbutton );
			}
            
		}
        
       function validateSeasonFormat(season)
       {
           var valid = false;
           //var regex2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/     // mm/dd/yyyy
           var regex = /^\d{4}(\/)\d{4}$/     // mm/dd/yyyy
           //var regex = /[^0-9]{4}\/[^0-9]{4}/;
           return regex.test(season);
           //return false;
       }       
       
       function validateDateFormatYYYYMMDD(_date)
       {
           var regex = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/     // yyyy/mm/dd
           
           return regex.test(_date);
           //return false;
       }   
       
       function validateScoreCardTeamScoresFormatOk()
       {
            var form = document.adminForm;
            
            var club_firstinnrunswickets = form.club_firstinnrunswickets.value;
            var opp_firstinnrunswickets = form.opp_firstinnrunswickets.value;
            var club_secondinnrunswickets = form.club_secondinnrunswickets.value;
            var opp_secondinnrunswickets = form.opp_secondinnrunswickets.value;
            
            var valid = true;
            var regex = /^([1-9]|[1-9][0-9]|[1-9][0-9][0-9])(\/)([0-9]|1[0])$/     //numeric < 999/numeric < 10
            
            if(club_firstinnrunswickets > "")
            {
                valid = valid & regex.test(club_firstinnrunswickets);
                if(!regex.test(club_firstinnrunswickets))
                {
                    alert("First innings club score ("+club_firstinnrunswickets+") is not formatted correctly. Example 223/10 or 321/8");
                }
                //alert("regex.test(club_firstinnrunswickets):"+regex.test(club_firstinnrunswickets));
            }
            
            if(opp_firstinnrunswickets > "")
            {
                valid = valid & regex.test(opp_firstinnrunswickets);
                if(!regex.test(opp_firstinnrunswickets))
                {
                    alert("First innings opponent score ("+opp_firstinnrunswickets+") is not formatted correctly. Example 223/10 or 321/8");
                }
                //alert("regex.test(opp_firstinnrunswickets):"+regex.test(opp_firstinnrunswickets));
            }
            
            if(club_secondinnrunswickets > "")
            {
                valid = valid & regex.test(club_secondinnrunswickets);
                if(!regex.test(club_secondinnrunswickets))
                {
                    alert("Second innings club score ("+club_secondinnrunswickets+") is not formatted correctly. Example 223/10 or 321/8.");
                }
                //alert("regex.test(club_secondinnrunswickets):"+regex.test(club_secondinnrunswickets));
            }
            
            if(opp_secondinnrunswickets > "")
            {
                valid = valid & regex.test(opp_secondinnrunswickets);
                if(!regex.test(opp_secondinnrunswickets))
                {
                    alert("Second innings opponent score ("+opp_secondinnrunswickets+") is not formatted correctly. Example 223/10 or 321/8.");
                }
                //alert("regex.test(opp_secondinnrunswickets):"+regex.test(opp_secondinnrunswickets));
            }
            
            return valid;
       }   
       
       function inningsDatesOk()
       {
           
           var form = document.adminForm;
           var str1  = form.firstinndate.value;
           var str2  = form.secondinndate.value;
           
           if(str2=="") return true;
           
           /*
           var dt1   = parseInt(str1.substring(0,2),10);
           var mon1  = parseInt(str1.substring(3,5),10);
           var yr1   = parseInt(str1.substring(6,10),10);
           var dt2   = parseInt(str2.substring(0,2),10);
           var mon2  = parseInt(str2.substring(3,5),10);
           var yr2   = parseInt(str2.substring(6,10),10);
           */
          // 4 Date format YYYY/MM/DD
          var yr1   = parseInt(str1.substring(0,4),10); 
          var mon1  = parseInt(str1.substring(5,7),10);
          var dt1   = parseInt(str1.substring(8,10),10);
          
          var yr2   = parseInt(str2.substring(0,4),10);
          var mon2  = parseInt(str2.substring(5,7),10);
          var dt2   = parseInt(str2.substring(8,10),10);
          
          var msg = "Innings date format must be yyyy-mm-dd.";
           
          var date1 = new Date(yr1, mon1, dt1);
          var date2 = new Date(yr2, mon2, dt2);
        
           if(date2 < date1)
           {
              return false;
           }
           else
           {
             return true;
           }
       } 
        

       
       function buildresultlist()
       {
            var form = document.adminForm;
            
            //find the selected opponent team
            var oppselection_val = form.oppteamid.options[form.oppteamid.options.selectedIndex].value; 
            var oppselection_txt = form.oppteamid.options[form.oppteamid.options.selectedIndex].text; 
            //find the selected home team 
            var hometeamselection_val = form.hometeamid.options[form.hometeamid.options.selectedIndex].value; 
            var hometeamselection_txt = form.hometeamid.options[form.hometeamid.options.selectedIndex].text; 
                       
            //create the required result options
            //0 - Select Result -
            //1 - Home team win
            //2 - Home team loose
            //3 - Match drawn
            //4 - Match abandoned
            
            form.resultlist.options.length = 0;
            form.resultlist.options[0] = new Option("- Select Result -", "0");
            form.resultlist.options[1] = new Option(hometeamselection_txt + " team win" , "1");
            form.resultlist.options[2] = new Option(hometeamselection_txt + " team loose", "2");
            form.resultlist.options[3] = new Option("Draw", "-3");
            form.resultlist.options[4] = new Option("Match abandoned", "-4");
            //updateParameters();
            return false;
       }
       </script>
		<form action="index.php" method="post" name="adminForm">

		<div class="col100">
            <fieldset class="adminform">
				<legend><?php echo JText::_( 'Scorecard' ); ?></legend>

				<table class="admintable">
				<tbody>
					<tr>
						<td width="20%" class="key">
							<label for="firstname">
								<?php echo JText::_( 'Season' ); ?>:
							</label>
						</td>
						<td width="20%">
                            <?php 
                            if($row->id > 0) 
                            {
                                ?>
                                <input class="inputbox" type="text" name="season" id="season" size="15" value="<?php echo $row->season;?>" />
                                <?php 
                            }
                            else
                            {
                                //new scorecard
                                ?> 
                                <input class="inputbox" type="text" name="season" id="season" size="15" value="<?php echo $row->currentseason;?>" />
                                <?php 
                            }
                            ?>
							
						</td>
                        <td width="20%" class="key">
							<label for="firstname">
								<?php echo JText::_( 'Division' ); ?>:
							</label>
						</td>
						<td width="20%">
							<input class="inputbox" type="text" name="division" id="division" size="20" value="<?php echo $row->division;?>" />
						</td>
                        <td width="20%" class="key">
							<label for="hometeamid">
								<?php echo JText::_( 'Club' ); ?>:
							</label>
						</td>
                        <td width="20%">
							<input class="inputbox" type="text" name="hometeamidfilter" id="hometeamidfilter" size="15" value="" onblur="document.forms[1].task.value='updatehometeamdropdown';document.forms[1].Submit.click();"/>
                            <div id="hometeamiddiv"><?php echo $lists['hometeamid']; ?></div>
                            <input  type="hidden" class="inputbox" type="text" name="hometeamidvalue" id="hometeamidvalue" size="0" value="<?php echo $row->teamidhome; ?>" />
						</td>
                        <td width="20%" class="key">
							<label for="firstname">
								<?php echo JText::_( 'Opponent' ); ?>:
							</label>
						</td>
                        <td width="20%">
							<input class="inputbox" type="text" name="oppteamidfilter" id="oppteamidfilter" size="15" value="" onblur="document.forms[1].task.value='updateoppteamiddropdown';document.forms[1].Submit.click();"/>
                            <div id="oppteamiddiv"><?php echo $lists['oppteamid']; ?><div>
						</td>						
					</tr>
                    <tr>
						<td width="20%" >
							
						</td>
						<td width="20%">
								<?php echo ' '; ?>
						</td>
                        <td width="20%">
							
						</td>
						<td width="20%">
								<?php echo ' '; ?>
						</td>
					</tr>
                    <tr>
                        <td width="20%" class="key">
							<label for="firstinndate">
								<?php echo JText::_( '1st Inn date' ); ?>:
							</label>
						</td>
						<td width="20%">
							<?
                                $inndate = $row->firstinndate > '' ? date('Y-m-d',strtotime($row->firstinndate)) : '';
                                echo JHTML::_('calendar', $inndate, 'firstinndate', 'firstinndate');
                            ?>
						</td>
                    </tr>
                    <tr>
                        <td width="20%" class="key">
							<label for="secondinndate">
								<?php echo JText::_( '2nd Inn date' ); ?>:
							</label>
						</td>
						<td width="20%">
							<?
                                $inndate2 = $row->secondinndate > '' ? date('Y-m-d',strtotime($row->secondinndate)) : '';
                                echo JHTML::_('calendar', $inndate2, 'secondinndate', 'secondinndate');
                            ?>
						</td>
                    </tr>
                    <tr>
						<td width="20%" >
							
						</td>
						<td width="20%">
								<?php echo ' '; ?>
						</td>
                        <td width="20%">
							
						</td>
						<td width="20%">
								<?php echo ' '; ?>
						</td>
					</tr>
                    <tr>
                        <td width="20%" class="key">
                            <?php echo JText::_( 'Scores' ); ?>:
                        </td>
                        <td width="20%">
                            <?php echo JText::_( 'Club' ); ?>
                        </td>
                        <td width="20%">
                            <?php echo JText::_( 'Opponent' ); ?>
                        </td>
					</tr>
                    <tr>
                        <td width="20%" class="key">
							<label for="club_firstinnrunswickets">
								<?php echo JText::_( '1st Inn (runs/wkts)' ); ?>:
							</label>
						</td>
						<td width="20%">
							<input class="inputbox" type="text" name="club_firstinnrunswickets" id="club_firstinnrunswickets" size="15" value="<?php echo $row->firstinnscore_home; ?>" />
						</td>
                        <td width="20%">
							<input class="inputbox" type="text" name="opp_firstinnrunswickets" id="opp_firstinnrunswickets" size="15" value="<?php echo $row->firstinnscore_opponent; ?>" />
						</td>
                    </tr>
                    <tr>
                        <td width="20%" class="key">
							<label for="club_secondinnrunswickets">
								<?php echo JText::_( '2nd Inn (runs/wkts)' ); ?>:
							</label>
						</td>
						<td width="20%">
							<input class="inputbox" type="text" name="club_secondinnrunswickets" id="club_secondinnrunswickets" size="15" value="<?php echo $row->secondinnscore_home; ?>" />
						</td>
                        <td width="20%">
							<input class="inputbox" type="text" name="opp_secondinnrunswickets" id="opp_secondinnrunswickets" size="15" value="<?php echo $row->secondinnscore_opponent; ?>" />
						</td>
                    </tr>
                    <tr>
						<td width="20%" >
							
						</td>
						<td width="20%">
								<?php echo ' '; ?>
						</td>
                        <td width="20%">
							
						</td>
						<td width="20%">
								<?php echo ' '; ?>
						</td>
					</tr>    
                    <tr>
						<td width="20%" class="key">
							<label for="result">
								<?php echo JText::_( 'Result' ); ?>:
							</label>
						</td>
						<td width="20%">
                            <?php
                            if($row->id>0)
                            {
                                echo $lists[resultlist];
                            }
                            else
                            {
                                echo '<select id="resultlist" class="inputbox" size="1" name="resultlist">'
                                .'<option value="0">- Select Result -</option>'
                                .'</select>';
                            }
                            ?>
							
						</td>
                        <td width="20%" class="key">
							<label for="resultdetails">
								<?php echo JText::_( 'By' ); ?>:
							</label>
						</td>
						<td width="20%">
							<input class="inputbox" type="text" name="resultdetails" id="resultdetails" size="30" value="<?php echo $row->resultdetails; ?>" />
                            <!--select id="resultdetaillist" class="inputbox" size="1" name="resultdetaillist">
                                <option value="0">Wickets</option>
                                <option value="1">Runs</option>
                            </select-->
						</td>
					</tr>			
                    <tr>
						<td width="20%" >
							
						</td>
						<td width="20%">
								<?php echo ' '; ?>
						</td>
                        <td width="20%">
							
						</td>
						<td width="20%">
								<?php echo ' '; ?>
						</td>
					</tr>
                    <tr>
                        <td width="20%" class="key">
							<label for="firstname">
								<?php echo JText::_( 'Published' ); ?>
							</label>
						</td>
						<td width="20%">
							<?php echo $lists['published']; ?>
						</td>
					</tr>
                    <tr>
                        <td width="20%">
                            <?php 
                            if($row->id == 0)
                            {   //<!--Here we should prob set the task that the form1 will post-->
                                echo '<a href="#" onclick="document.forms[1].task.value=\'buildteamstatslist\';document.forms[1].Submit.click();">Generate player scorecard</a>';
                            }
                            ?>
                        </td>
					</tr>
                    
				</tbody>
				</table>
                
                <!--Show the stats table for the existing scorecard. This is built by the controller-->
                <?php if($row->id > 0) echo $statstable; ?> 
                <div id="update">
                
                </div>
                <div id="ajaxLoader" style="left: 600px; top: 300px; width: 50px; position: absolute;  height: 50px"/>
            </fieldset>
		</div>
		<div class="clr"></div>

		<input type="hidden" name="c" value="scorecard" />
		<input type="hidden" name="option" value="com_statzone" />
		<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
		<input type="hidden" name="task" value="edit" />
		<?php echo JHTML::_( 'form.token' ); ?>
		</form>
        
        <?php 
            // add mootools
            JHTML::_('behavior.mootools');
        ?>
        <script language="javascript" type="text/javascript">
        window.addEvent('domready', function()
        {
        $('form1').addEvent('submit', function(e)
            {
                // Stop the form from submitting
                new Event(e).stop();
                // Update the page
                //alert("about to send the ajax request");
                //this.send({ update: $('update') });
                $('ajaxLoader').innerHTML = "<img src=\"components/com_statzone/images/ajax-loader.gif\" alt=\"Loading...\" title=\"Loading...\" />";
                this.send({ onComplete: function(response, responseXML)
                {
                    //alert('AJAX Response Received');
                    // get the XML nodes
                    var root = responseXML.documentElement;
                    var inputrows = root.getElementsByTagName('inputrows').item(0);
                    
                    //the XML should let us know what element to update as well!
                    // prepare the XHTML
                    var updateValue = inputrows.firstChild.nodeValue;
                    
                    if(document.form1.task.value=='buildteamstatslist')
                    {
                        // update the page element 'update'
                        //$('update').empty().setHTML(updateValue);
                        $('update').innerHTML  = updateValue;
                        //May need to generate the dom directly
                  
                    }
                    else if(document.form1.task.value=='updatehometeamdropdown')
                    {
                        $('hometeamiddiv').innerHTML  = updateValue;
                        //var form = document.adminForm;
                        //form.hometeamid.options.length = 0;
                        //form.hometeamid.options[0] = new Option("- Select Result -", "0");
                    }
                    else if(document.form1.task.value=='updateoppteamiddropdown')
                    {
                        $('oppteamiddiv').innerHTML  = updateValue;
                    }
                    $('ajaxLoader').innerHTML = "";
                    //alert(updateValue);
                }});
            });
        });
        
        function updateParameters()
        {
            var hometeamselection = document.adminForm.hometeamid.options[document.adminForm.hometeamid.options.selectedIndex].value; 
            var opponentteamselection = document.adminForm.oppteamid.options[document.adminForm.oppteamid.options.selectedIndex].value; 
            var firstInnDate =  document.adminForm.firstinndate.value;
            //alert("hometeam id to be sent = " + hometeamselection + " document.form1.hometeamidvalue is null= " + document.forms[1].hometeamidvalue == null);
            var ajaxFunction = document.forms[1].task.value;
            // some validation to ensure that both home team & opponent team, firstinndate exists
            if(ajaxFunction=='buildteamstatslist' && hometeamselection <= 0 | opponentteamselection <= 0 | document.adminForm.firstinndate.value == "")
            {
                alert("Please first select the teams and supply a date for the first innings.");
                return false;
            }
            document.adminForm.hometeamidvalue.value = "" + hometeamselection;
            document.form1.hometeamidvalue.value = "" + hometeamselection;
            document.form1.oppteamid.value = "" + opponentteamselection;
            document.form1.firstinndate.value = firstInnDate;
            
            document.form1.hometeamidfilter.value = document.adminForm.hometeamidfilter.value;
            document.form1.oppteamidfilter.value = document.adminForm.oppteamidfilter.value;
            return true;
        }
       </script>
        <form id="form1" method="post" name="form1" action="<?php 
                $routurl = 'index.php?option=com_statzone#'; 
                echo JRoute::_($routurl); ?>">
                
             <script>
            
           </script>
            <input  type="hidden" name="id" type="text" id="id" size="0"/>
            
            <input  type="hidden" class="inputbox" type="text" name="hometeamidvalue" id="hometeamidvalue" size="0" value="" />
            <input  type="hidden" class="inputbox" type="text" name="oppteamid" id="oppteamid" size="0" value="" />
            <input  type="hidden" class="inputbox" type="text" name="firstinndate" id="firstinndate" size="0" value="" />
            <input  type="hidden" class="inputbox" type="text" name="hometeamidfilter" id="hometeamidfilter" size="0" value="" />
            <input  type="hidden" class="inputbox" type="text" name="oppteamidfilter" id="oppteamidfilter" size="0" value="" />
            
            <input name="format" type="hidden" id="format" value="raw" />
            <input name="view" type="hidden" id="view" value="wfaq" />
            <div class="clr" ><input name="Submit" type="submit" value="" size="0" onclick="return updateParameters();" bgcolor="#ffffff"/></div>
            
            <input type="hidden" name="c" value="scorecard" />
            <input type="hidden" name="option" value="com_statzone" />
            <input type="hidden" name="task" value="buildteamstatslist" />
        </form>
		<?php
	}
    
    //
    //View display function to view the list scorecards
    //
    function scorecards( &$rows, &$pageNav, &$lists )
    {
        StatZoneViewScorecards::setScorecardsToolbar();
        $user =& JFactory::getUser();
		JHTML::_('behavior.tooltip');
        ?>
		<form action="index.php?option=com_statzone" method="post" name="adminForm">
        <table>
        	<tr>
                <td align="left" width="100%">
                    <?php echo JText::_( 'Filter' ); ?>:
                    <input type="text" name="search" id="search" value="<?php echo $lists['search'];?>" class="text_area" onchange="document.adminForm.submit();" />
                    <button onclick="this.form.submit();"><?php echo JText::_( 'Go' ); ?></button>
                    <button onclick="document.getElementById('search').value='';this.form.submit();"><?php echo JText::_( 'Filter Reset' ); ?></button>
                    <!--button onclick="document.getElementById('search').value='';this.form.getElementById('filter_provinceid').value='0';this.form.getElementById('filter_state').value='';this.form.submit();"><?php //echo JText::_( 'Filter Reset' ); ?></button-->
                </td>
                <td nowrap="nowrap">
                    <?php
                    //echo $lists['provinceid'];
                    //echo $lists['hometeamid'];
                    //echo $lists['oppteamid'];
                    ?>
                </td>
		    </tr>
		</table>

        <table class="adminlist">
			<thead>
				<tr>
					<th width="2%">
						<?php echo JText::_( 'Num' ); ?>
					</th>
					<th width="2%" align="center">
						<input type="checkbox" name="toggle" value=""  onclick="checkAll(<?php echo count( $rows ); ?>);" />
					</th>
					<th width="10%" nowrap="nowrap" class="title">
						<?php echo JHTML::_('grid.sort',  'Date', 'scorecard.firstinndate', @$lists['order_Dir'], @$lists['order'] ); ?>
					</th>
                    <th width="10%" nowrap="nowrap" class="title">
						<?php echo JHTML::_('grid.sort',  'Home team', 'hometeamname', @$lists['order_Dir'], @$lists['order'] ); ?>
					</th>
                    <th width="10%" nowrap="nowrap" class="title">
						<?php echo JHTML::_('grid.sort',  'Away team', 'awayteamname', @$lists['order_Dir'], @$lists['order'] ); ?>
					</th>
					<th width="5%" nowrap="nowrap">
						<?php echo JHTML::_('grid.sort',   'Inn', 'inn', @$lists['order_Dir'], @$lists['order'] ); ?>
					</th>
                    <th width="20%" nowrap="nowrap">
						<?php echo JHTML::_('grid.sort',   'Result', 'result', @$lists['order_Dir'], @$lists['order'] ); ?>
					</th>
					<th width="5%" nowrap="nowrap">
						<?php echo JHTML::_('grid.sort',   'Published', 'scorecard.published', @$lists['order_Dir'], @$lists['order'] ); ?>
					</th>
					<th width="1%" nowrap="nowrap">
						<?php echo JHTML::_('grid.sort',   'ID', 'id', @$lists['order_Dir'], @$lists['order'] ); ?>
					</th>
				</tr>
			</thead>
			<tfoot>
				<tr>
					<td colspan="13">
						<?php echo $pageNav->getListFooter(); ?>
					</td>
				</tr>
			</tfoot>
			<tbody>
			<?php
            $k = 0;
			for ($i=0, $n=count( $rows ); $i < $n; $i++) {
				$row = &$rows[$i];

				$row->id	= $row->id;
				$link		= JRoute::_( 'index.php?option=com_statzone&c=scorecard&task=edit&cid[]='. $row->id );
                                                
				//if( $row->imptotal <= 0 ) {
				//	$row->imptotal	=  JText::_('unlimited');
				//}

                $row->published = $row->published;
				$published		= JHTML::_('grid.published', $row, $i );
				$checked		= JHTML::_('grid.checkedout',   $row, $i );
                
				?>
				<tr class="<?php echo "row$k"; ?>">
					<td align="center">
						<?php echo $pageNav->getRowOffset($i); ?>
					</td>
					<td align="center">
						<?php echo $checked; ?>
					</td>
					<td align="center">
                        <span class="editlinktip hasTip" title="<?php echo JText::_( 'Edit' );?>::<?php echo $row->hometeamname .' vs '. $row->awayteamname;?>">
                			<a href="<?php echo $link; ?>">
								<?php echo date('Y-m-d',strtotime($row->firstinndate)) . '<br>'; 
                                      if($row->secondinndate > '') echo date('Y-m-d',strtotime($row->secondinndate));
                                ?></a>
						</span>
						
					</td>
                    <td align="center">
						<?php echo $row->hometeamname;?>
					</td>
					<td align="center">
						<?php echo $row->awayteamname;?>
					</td>
					<td align="center">
						<?php echo $row->inn;?>
					</td>
                    <td align="center">
						<?php 
                            echo $row->result ; 
                            if($row->resultdetails > '') echo ' by '.$row->resultdetails;
                        ?>
					</td>
                    <td align="center">
						<?php echo $published;?>
					</td>
					<td align="center">
						<?php echo $row->id; ?>
					</td>
				</tr>
				<?php
				$k = 1 - $k;
			}
			?>
			</tbody>
			</table>

		<input type="hidden" name="c" value="scorecard" />
		<input type="hidden" name="option" value="com_statzone" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		<input type="hidden" name="filter_order" value="<?php echo $lists['order']; ?>" />
		<input type="hidden" name="filter_order_Dir" value="<?php echo $lists['order_Dir']; ?>" />
		<?php echo JHTML::_( 'form.token' ); ?>
		</form>
		<?php
    }
}
